package ics.nodes;

import ics.DateParentNode;

import java.time.LocalDateTime;

public class Rrule extends DateParentNode {

    // todo 添加周
// FREQ表示重复的单位，如按周重复、按年重复
    public static final String SECONDLY = "SECONDLY";
    public static final String MINUTELY = "MINUTELY";
    public static final String HOURLY = "HOURLY";
    public static final String DAILY = "DAILY";
    public static final String WEEKLY = "WEEKLY";
    public static final String MONTHLY = "MONTHLY";
    public static final String YEARLY = "YEARLY";

    private String freq, wkst, until, count, interval, byday;

    public Rrule() {

    }

    public void setValue(String freq, int interval, int count) {
        setName(Constants.RRULE);
        String stringBuffer = "FREQ=" + freq + ";" +
                "INTERVAL=" + interval + ";" +
                "BYDAY=" + getZonedDateTime().getDayOfWeek().toString() + ";" +
                "COUNT=" + ++count + ";";
        setValue(stringBuffer.toUpperCase());
    }

    public void setValue(String freq, int interval, LocalDateTime endTIme) {
        setZonedDateTime(endTIme.atZone(getZoneId()));
        setName(Constants.RRULE);
        String stringBuffer = "FREQ=" + freq + ";" +
                "INTERVAL=" + interval + ";" +
                "BYDAY=" + getZonedDateTime().getDayOfWeek().toString() + ";" +
                "UNTIL=" + endTIme.format(defaultdateTimeFormatter);
        setValue(stringBuffer.toUpperCase());
    }
}
